package com.bulemobi.activity.ac_user_centre;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.bulemobi.net.tsz.afinal.FinalHttp;
import com.bulemobi.net.tsz.afinal.annotation.view.ViewInject;
import com.bulemobi.net.tsz.afinal.http.AjaxCallBack;
import com.bulemobi.net.tsz.afinal.http.AjaxParams;
import com.bulemobi.urlCentre.UrlCentre;
import com.bulemobi.view.BaseActivity;
import com.jsyh.hcb.R;

/**
 * Created by 武 on 2014/9/21 0021.
 * 设置交易密码
 */
public class Ac_Bank_Set_PassWord extends BaseActivity implements View.OnClickListener {
    @ViewInject(id = R.id.tv_confirm)
    TextView tv_confirm;
    @ViewInject(id = R.id.ed_firstPassWord)
    EditText ed_first;
    @ViewInject(id = R.id.ed_secondPassWord)
    EditText ed_second;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_bank_set_password);
        initView();
    }

    private void initView() {
        tv_confirm.setOnClickListener(this);
    }

    private void requestHttp(String url, AjaxParams params, final String type) {
        FinalHttp http = new FinalHttp();
        http.post(url, params, new AjaxCallBack<Object>() {
            @Override
            public void onStart() {
                showProgressDialog();
                super.onStart();
            }

            @Override
            public void onSuccess(Object o) {
                closeProgressDialog();
                if (type.equals("change")) {
                    openActivity(Ac_Add_BankCard_Success.class);
                    finish();
                }
                super.onSuccess(o);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                closeProgressDialog();
                super.onFailure(t, errorNo, strMsg);
            }
        });
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == tv_confirm.getId()) {
            if (TextUtils.isEmpty(ed_first.getText().toString())) {
                showToastShort(getResources().getString(R.string.error_trade_pwd));
                return;
            }
            if (TextUtils.isEmpty(ed_second.getText().toString())) {
                showToastShort(getResources().getString(R.string.error_trade_pwd));
                return;
            }
            if (!ed_first.getText().toString().equals(ed_second.getText().toString())) {
                showToastShort(getResources().getString(R.string.error_trade_again_pwd));
                return;
            } else {
                AjaxParams params = new AjaxParams();
                params.put("modifyFlag", "2");
                params.put("payPasswordConfirm", ed_first.getText().toString());
                params.put("confirmPayPassword", ed_second.getText().toString());
                requestHttp(UrlCentre.ModifyUserInfo, params, "change");

//                openActivity(Ac_Add_BankCard_Success.class);
//                finish();
            }
        }
    }
}
